package per.example.arpproject.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.io.File;

/**
 * @author yaozhang Li
 * @ TO DO
 * @createTime 2023/7/13 19:56
 **/
@Configuration
public class MyFilePathConfigurer extends WebMvcConfigurationSupport {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        String rootPath = System.getProperty("user.dir") + File.separator + "spritData"+File.separator;

        //项目内静态文件映射，仍然可以访问到静态资源
        registry.addResourceHandler("/spritData/**").addResourceLocations("file:"+rootPath);

        // 解决静态资源无法访问
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        // 解决swagger无法访问
        registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        // 解决swagger的js文件无法访问
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }

    public static void main(String[] args) {
        String rootPath = System.getProperty("user.dir") + File.separator + "spritData";
        System.out.println(rootPath);
    }
}
